package com.canbot.u05.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.canbot.u05.R;


/**
 * @author  zmp 语音录入对话框
 */

public class GuideRecordDialog extends Dialog implements View.OnClickListener {

        private MyRecordView myRecordView;

        public GuideRecordDialog(Context context,IRecodeListener recodeListener) {
                super(context, R.style.MyDialogStyle);
                this.recodeListener = recodeListener;
                setCancelable(false);
                setCustomDialog();

        }

        private void setCustomDialog() {
                View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_recode_voice, null);
                super.setContentView(mView);
                myRecordView = (MyRecordView) findViewById(R.id.mrv);
                myRecordView.setErrorListener(new MyRecordView.IErrorListener() {
                        @Override
                        public void onError() {
                                dismiss();
                                recodeListener.error();
                        }
                });
                findViewById(R.id.finish_bt).setOnClickListener(this);
                findViewById(R.id.cancel_bt).setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
                switch (v.getId()) {
                        case R.id.finish_bt:
                                String fileName = myRecordView.ok();
                                dismiss();
                                recodeListener.finish(fileName);
                                break;
                        case R.id.cancel_bt:
                                myRecordView.cancel();
                                dismiss();
                                recodeListener.cancel();
                                break;
                }
        }

        @Override
        public void show() {
                super.show();
                myRecordView.startRecord();
        }

        private IRecodeListener recodeListener;

        public interface IRecodeListener {

                void finish(String fileName);

                void cancel();

                void error();
        }
}
